#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>

const int PORT = 23816;

int main(int argc, char* argv[])
{
	//create socket for connection
	int cs = socket(AF_INET, SOCK_STREAM, 0);
	if(cs == -1){
		perror("Can't create socket");
		exit(EXIT_FAILURE);
	}

	//I assume server listening on loopback address
	//otherwise gethostbyaddr or getaddrinfo must be used
	struct sockaddr_in peer_adress = {
		AF_INET,
		htons(PORT),
		{htonl(INADDR_LOOPBACK)},
	};
	connect(cs, (struct sockaddr *)&peer_adress, sizeof(peer_adress));
	if(cs == -1){
		perror("Can't connect to server");
		exit(EXIT_FAILURE);
	}
	
	//send program name and and all params to server
	for(int i=0; i<argc; i++){
		int written = send(cs, argv[i], strlen(argv[i]), 0);
		
		if(written == -1){
			perror("Error during sent bytes");
			exit(EXIT_FAILURE);
		}
	}

	close(cs);
}
